package sg.ImageShack.components
{
	import flash.display.Screen;
	import flash.events.MouseEvent;
	
	import mx.controls.scrollClasses.ScrollThumb;
	import mx.core.Window;
	
	import sg.ImageShack.models.AppContext;

	public class BaseWindow extends Window
	{
		[Bindable]
		public var ctx : AppContext;
		public var holder : GlowCanvas;
		public var glowAlpha : Number = .7;
		
		public function BaseWindow()
		{
			super();
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
			setStyle("showFlexChrome", false);
			ctx = AppContext.ctx;
			alwaysInFront = true;
			systemChrome = 'none';
			layout = "absolute";
			transparent = true;
			type = 'utility'
		}
		override protected function commitProperties():void
		{
			super.commitProperties();
			nativeWindow.x = Screen.mainScreen.bounds.width / 2 - width / 2;
			nativeWindow.y = Screen.mainScreen.bounds.height / 2 - height + 100;
		}
		override protected function createChildren():void
		{
			holder = new GlowCanvas;
			rawChildren.addChild(holder);
			holder.x = 20;
			holder.y = 20;
			holder.width = width - 40;
			holder.height = height - 40;
			holder.color = 0x000000;
			holder.glowSize = 20;
			holder.glowAlpha = glowAlpha;
			
			super.createChildren();
		}
		private function onMouseDownHandler(event : MouseEvent):void
		{
			if (event.target is ScrollThumb) return;
			nativeWindow.startMove();
		}
	}
}